package com.zyx.javademo.optional;

import java.util.Optional;
import java.util.Random;
import java.util.function.Consumer;
import java.util.stream.Stream;

/**
 * @author Yaxi.Zhang
 * @since 2021/12/3 13:23
 * desc: OptionalDemo
 */
public class OptionalDemo {
    public static void main(String[] args) {
        Random r = new Random();
        for (int i = 0; i < 10; i++) {
            int num = r.nextInt(10);
            Optional<Integer> first = Stream.of(num).filter(x -> x % 2 == 0).findFirst();
            System.out.println("num = " + num);
            if (first.isPresent()) {
                System.out.println("num is even...");
            } else {
                System.out.println("num is odd...");
            }
            first.ifPresent(j -> System.out.println("present =====>>>>> " + j));
            System.out.println("or else =====>>>>> " + first.orElse(3000));
            System.out.println("**************************************************");
        }
    }
}
